package cn.hy.machine;


import cn.hy.entity.Order;
import cn.hy.enums.OrderStatusEnum;
import cn.hy.events.OrderStatusChangeEvent;
import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
import org.springframework.stereotype.Component;


@Component
public class OrderStatusMachinePersist implements StateMachinePersist<OrderStatusEnum, OrderStatusChangeEvent, Order> {

    @Override
    public void write(StateMachineContext<OrderStatusEnum, OrderStatusChangeEvent> context, Order contextObj) {
        // 这里不做任何持久化工作
    }

    @Override
    public StateMachineContext<OrderStatusEnum, OrderStatusChangeEvent> read(Order contextObj) {
        return new DefaultStateMachineContext<>(OrderStatusEnum.getByCode(contextObj.getStatus()), null, null, null, null, "orderStatusMachine");
    }

}
